package com.kjs.web.jwt.handler;

import com.alibaba.fastjson.JSONObject;
import com.kjs.common.consts.ResultConst;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定403返回值
 */
@Component
public class RestAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) {
        //response.setHeader("Access-Control-Allow-Origin", "*");
        JSONObject jr = new JSONObject();
        jr.put("err", ResultConst.ERR_AUTH_NEED_LOGIN);
        jr.put("ver", 1);
        ResponseHelper.print(response, jr.toString(), 403);
    }
}
